package Server.Dwc.fkfish;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Vector;

import org.apache.commons.beanutils.BeanUtils;

import net.sf.json.*;
import redis.protocal.DbInfoMgr;
import redis.protocal.UserRedisInfo;
import Server.Agent.GameAgent;
import Server.Agent.GameDB;
import Server.Model.Base.IRoom;
import Server.Model.Base.IServerUserItem;
import Server.Model.Base.SHMUser;
import Server.Model.Hall.QpGameMgr;
import Server.Model.Hall.dthall;
import club.ClubRedis;
import common.routine.PublishDef;
import Server.Model.Base.SecShmUser;
import Server.Model.Base.UserGoldChange;
import Server.Model.Base.UserRmbChange;

public class FkFishTable extends IRoom {
	//global variable
	public static HashMap<Integer,FishConfig> g_mapFishCfg = new HashMap<Integer,FishConfig>();
	public static List<Integer> g_vecCannonLevels = new ArrayList<Integer>();
	public static List<Integer> g_needCoins = new ArrayList<Integer>();
	HashMap<Integer,FishInfo> m_mapFishs = new HashMap<Integer,FishInfo>();
	HashMap<Integer,FishInfo> m_mapOtherFishs = new HashMap<Integer,FishInfo>();
	HashMap<Integer,Integer> m_mapFishNumber = new HashMap<Integer,Integer>();
	public int m_iBase;
	public long m_LastYuChaoTime;
	public long m_LastFreezeTime;
	public int m_iNextFishID;
	MSG_AddFish[] m_vecAddFishHistory = new MSG_AddFish[50];
	@Override
	public int GetID() {
		return m_dwTableID;
	};

	@Override
	public int GetCreator() {
		return m_Creator;
	}
	@Override
	public String GetType() {
		return "FKFISH";
	};
	@Override
	public void OnClientClose(int uid) {
		OnUserStandUp(uid,false);
	};

	public boolean SendData(int wChairID, String sData) {
		if (wChairID == Constants.INVALID_CHAIR) {
			for (short i = 0; i < m_pIUserItem.length; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					if (m_pIUserItem[i].isAndroidUser == 0) {
						dthall.getInstance().onSend(m_pIUserItem[i].dwUserID, sData);
					} else {
						// mPlayers[i].SendGameMessage(wSubCmdID, pData,
						// wDataSize, data);
					}
				}
			}

			return true;
		} else {
			if (wChairID >= m_pIUserItem.length) {
				dthall.getInstance().onSend(wChairID, sData);
			} else if (m_pIUserItem[wChairID].dwUserID > 0) {
				if (m_pIUserItem[wChairID].isAndroidUser == 0) {
					dthall.getInstance().onSend(m_pIUserItem[wChairID].dwUserID, sData);
				} else {
				}
				return true;
			}
		}

		return false;
	}

	int m_dwLastDoCmdTime;

	public int CanSit(int _Uid) {
		
		if (m_locked != 0) {
			return 13;
		}

		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID == _Uid) {
				SUBCMD_S_OnLine cmd = new SUBCMD_S_OnLine();
				cmd.uid = _Uid;
				cmd.seat = i;
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
				return i;
			}
		}

		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null && isZuJuType()) {
			if (m_payWay.equalsIgnoreCase("CLUBPAY") || m_payWay.equalsIgnoreCase("WINPAY")) {
				if(m_payWay.equalsIgnoreCase("CLUBPAY")){
					for (int i = 0; i < m_maxUserNum; i++) {
						if (m_pIUserItem[i].dwUserID == 0) {
							return i;
						}
					}
					return 12;
				}
				if (user.getGem(0) < m_byCostGem * m_maxUserNum) {
					return 11;
				}
			}else{
				if (m_payWay.equalsIgnoreCase("AAPAY") )
				{
					if (user.getGem(0) < m_byCostGem) {
						return 11;
					}
				}
			}
		}

		if(user != null && isGoldType()){
			if(user.getCoin(0) < m_ruchang){
				return 21;
			}
		}
		if(user != null && isDwcType()){
			if(user.getCoin(0) < m_ruchang){
				return 21;
			}
		}
	
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				return i;
			}
		}
		return 12;
	};
	long m_lStartTime;
	int needGameStats;
	long needDealTime;
	int m_dwTableID;
	long m_dismissTimer;


	boolean m_bGameStarted;
	boolean m_bTableStarted;
	int m_byRound;
	int m_byMaxRound;
	int m_wFaPaiDelay;
	
	int m_nextUser = 0;
	public int m_almsTime = 3;
	public int m_byCostGem;
	public String m_payWay;
	public String m_strParam;
	public String m_strRoomDesc;
	public String[] m_vecParam;

	GameLogic m_GameLogic = new GameLogic();
	String m_curStage;
	
	int m_locked = 0;
	public int m_maxUserNum = 4;
	public int m_vecWinScore[] = new int[m_maxUserNum];
	public int m_vecLoseScore[] = new int[m_maxUserNum];
	public int m_vecCardType[] = new int[m_maxUserNum];
	public int m_vecRoundScore[] = new int[m_maxUserNum];
	public int m_vecResultScore[] = new int[m_maxUserNum];
	public double m_doubleVecResultScore[] = new double[m_maxUserNum];
	IServerUserItem m_pIUserItem[] = new IServerUserItem[m_maxUserNum];
	{
		for (int i = 0; i < m_maxUserNum; i++) {
			m_pIUserItem[i] = new IServerUserItem();
		}
	}
	Map<Integer, Integer> m_mapStartIndex = new HashMap<Integer, Integer>();
	public int rdRate;
	public int lastRateTime;
	int m_byAgreeDismiss[] = new int[m_maxUserNum];

	public int m_Creator;
	
	int[] m_UserStatus = new int[m_maxUserNum];
	int UserCntReady = 0;
	long startDealTime = 30;

	FkFishTable() {
		m_bTableStarted = false;
		m_lStartTime = System.currentTimeMillis() / 1000;
		m_bRemove = false;
		m_byCostGem = 0;
		m_payWay = "FZPAY";
		
		m_strParam = "";
		m_strRoomDesc = "";
		setRoomStarted(true);
	}

	void Init(int cbReason) {
		m_iBase = 0;
		m_LastYuChaoTime = System.currentTimeMillis();
		m_LastFreezeTime = 0;
		m_iNextFishID = 0;
		rdRate = 0;
		lastRateTime = 0;
		m_dwLastDoCmdTime = 0;
		m_bGameStarted = false;
		m_wFaPaiDelay = 0;
		UserCntReady = 0;
		startDealTime = 30;
		for (int i = 0; i < m_maxUserNum; i++) {
			m_vecCardType[i] = 0;

			m_vecRoundScore[i] = 0;
			m_UserStatus[i] = 0;
		}
		switch (cbReason) {
		case Constants.INIT_TOTAL: {
			m_dismissTimer = 0;
			for(int i = 0;i < m_maxUserNum;i++){
				m_byAgreeDismiss[i] = 0;
			}
			m_byRound = 0;
			m_byMaxRound = 0;
			for (int i = 0; i < m_maxUserNum; i++) {
				m_vecWinScore[i] = 0;
				m_vecLoseScore[i] = 0;
				m_vecResultScore[i] = 0;
				m_doubleVecResultScore[i] = 0;
			}
		}
			break;
		case Constants.INIT_FIRST_ROUND: {

		}
			break;
		case Constants.INIT_NEWROUND: {

		}
			break;
		}
	}

	void KickRobots() {
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
	}

	boolean HasRobot() {
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				return true;
			}
		}
		return false;
	}

	void SendAvatar(int _Uid) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}

		String iter = dthall.getInstance().Handle_OnGetUserAvatar(_Uid);

		SUBCMD_S_Avatar cmd = new SUBCMD_S_Avatar();
		cmd.m_lUid = _Uid;
		if (iter != null) {
			cmd.szAvatarURL = iter;
		} else {
			cmd.szAvatarURL = PublishDef.getDefaultHeadAvatar();
		}

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

	}
	public void SendLocationData(SHMUser user) {
		JSONObject data = new JSONObject();
		data.put("loc", user.getGpsLocInfo());
		data.put("uid", user.getUid());
		data.put("command", "GPS_LOC");
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if(other != null){
						data.put("uid", other.getUid());
						data.put("loc", other.getGpsLocInfo());
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}

	public void SendGpsData(SHMUser user) {
		JSONObject data = new JSONObject();
		List<Double> gpsData = user.getLocateInfo();
		data.put("lng", gpsData.get(0));
		data.put("lat", gpsData.get(1));
		data.put("command", "GPS_DATA");
		data.put("uid", user.getUid());
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if (other != null) {
						gpsData = other.getLocateInfo();
						data.put("uid", other.getUid());
						data.put("lng", gpsData.get(0));
						data.put("lat", gpsData.get(1));
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}
	public void OnUserSit(int _Uid) {
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		int wChairID = -1;
		for(int i = 0;i < 4;i++){
			if(m_pIUserItem[i].dwUserID == _Uid){
				wChairID = i;
				break;
			}
		}
		if(wChairID < 0){
			for(int i = 0;i < 4;i++){
				if(m_pIUserItem[i].dwUserID == 0){
					m_pIUserItem[i].dwUserID = _Uid;
					wChairID = i;
					break;
				}
			}
		}
		if(wChairID >= 0){
			UserRedisInfo redisData = user.getUserRedisInfo();
			int fishCannonLevel = redisData.getFishIntValue("CannonLevel");
			m_pIUserItem[wChairID].cannonLevel = fishCannonLevel;
			//获得属性
			if(this.isDwcType()){
				m_pIUserItem[wChairID].lUserRmb = user.getRmb1v1Value();
			}else if(this.isGoldType()){
				m_pIUserItem[wChairID].lUserCoin = user.getCoin(0);
			}
			int iCannonNum = g_vecCannonLevels.size();
			if(m_pIUserItem[wChairID].cannonLevel >= iCannonNum){
				m_pIUserItem[wChairID].cannonLevel = iCannonNum - 1;
			}
			if(m_pIUserItem[wChairID].cannonLevel == 0){
				m_pIUserItem[wChairID].cannonLevel = 1;
			}
			
			for(int i = 1;i < iCannonNum;i++){
				if(g_vecCannonLevels.get(i -1 ) < m_iBase && g_vecCannonLevels.get(i) >= m_iBase){
					if(m_pIUserItem[wChairID].cannonLevel <= i){
						m_pIUserItem[wChairID].cannonLevel = i;
					}
					break;
				}
			}
			int iCost = g_vecCannonLevels.get(m_pIUserItem[wChairID].cannonLevel % iCannonNum);
			if(iCost <= m_iBase){
				iCost = m_iBase;
			}
		}
	}

	int FindSeat(long _Uid) {
		for (int bySeatID = 0; bySeatID < m_maxUserNum; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}
	int random(int iMin, int iMax) {
		Random ra = new Random();
		return ra.nextInt(iMax - iMin) + iMin;
	}

	public void memcpy(int[] o, int[] b, int l) {
		for (int i = 0; i < l; i++) {
			o[i] = b[i];
		}
	}


	int GetPlayerCount() {
		int cntPlayer = 0;
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	int GetRobotCount() {
		int cntPlayer = 0;
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	public void OnUserStandUp(int _Uid,boolean leaveroom) {
		int wChairID = FindSeat(_Uid);
		
		if(m_bTableStarted == false && wChairID != 0 && leaveroom == true){
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}


		if (m_bTableStarted == false && leaveroom == true) {
			if (wChairID > 0 && wChairID < m_maxUserNum) {
				m_pIUserItem[wChairID].Init();
				QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			} else {
			}
		} else {
			if (wChairID < m_maxUserNum) {
				m_pIUserItem[wChairID].cbOnline = Constants.US_OFFLINE;
			}
		}	
	}
	public void SetParam(String szParam) {
		m_strParam = szParam;
		
		m_vecParam = m_strParam.split(";");
	}

	public void SetDesc(String szDesc) {
		m_strRoomDesc = szDesc;

	}

	boolean SendGameScene(int _Uid, int bGameStatus) {
		int wChairID = FindSeat(_Uid);
		if(wChairID >= m_maxUserNum)
		{
			return false;
		}
		if (m_strParam.length() > 0) {
			String tmpRoomDesc = m_strRoomDesc;
			
			SUBCMD_S_Param cmd = new SUBCMD_S_Param();
			cmd.m_dwTableID = m_dwTableID;
			cmd.szParam = m_strParam;
			cmd.szRoomDesc = tmpRoomDesc;
			SendData(_Uid, cmd.getJsonData());
		}
		
		int cntUser = 0;
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntUser++;
			}
		}
		{
			SUBCMD_S_Table cmd = new SUBCMD_S_Table();
			cmd.m_dwTableID = m_dwTableID;// ����ID
			cmd.m_bGameStarted = m_bGameStarted ? 1 : 0;// �Ƿ�ʼ
			cmd.m_bTableStarted = m_bTableStarted ? 1 : 0;// �Ƿ�ʼ
			cmd.m_byRound = m_byRound;
			cmd.m_byMaxRound = m_byMaxRound;
			cmd.m_cntUser = cntUser;// ���
			cmd.m_cntLookon = 1;// ����
			Constants.memset(cmd.m_seatInfo, 0, Constants.sizeof(cmd.m_seatInfo));

			for (int i = 0; i < m_maxUserNum; i++) {
				cmd.m_seatInfo[i].m_lUid = m_pIUserItem[i].dwUserID;// UID
				cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserScore;// COIN
				cmd.m_seatInfo[i].m_NickName = m_pIUserItem[i].szNickName;// NICKNAME
				cmd.m_seatInfo[i].m_iBetCoin = 0;//
				cmd.m_seatInfo[i].m_cbGender = m_pIUserItem[i].cbGender;
				cmd.m_seatInfo[i].m_iAvatar = m_pIUserItem[i].dwFaceID;//
				cmd.m_seatInfo[i].m_cbUserStatus = m_pIUserItem[i].cbUserStatus;// �û�״̬
				cmd.m_seatInfo[i].m_iVipLevel = m_pIUserItem[i].cbVipLevel;// VIP
																			// LEVEL
				cmd.m_seatInfo[i].m_iTitle = 0;// �ƺ�
				cmd.m_seatInfo[i].m_isLookon = 0;// �Ƿ����
				cmd.m_seatInfo[i].szIP = m_pIUserItem[i].szIP;// NICKNAME
				if(this.isGoldType())
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserCoin;
				else if(this.isDwcType())
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserRmb;
			}

			SendData(_Uid, cmd.getJsonData());
			for (int i = 0; i < m_maxUserNum; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					SendAvatar(m_pIUserItem[i].dwUserID);
				}
			}
		}

		if (m_bTableStarted == true) {//=============================================
			SUBCMD_S_STAGE cmd = new SUBCMD_S_STAGE();

			cmd.szStage = m_curStage;
			cmd.needDealTime = (int) needDealTime;
			for (int i = 0; i < m_maxUserNum; i++) {
				cmd.m_vecCardType[i] = m_vecCardType[i];
				cmd.m_vecRoundScore[i] = m_vecRoundScore[i];
			}
			
			for (int k = 0; k <2; k++) {
				//
			}
			
			SendData(_Uid, cmd.getJsonData());
		}

		switch (bGameStatus) {
		case Constants.GS_FREE: // ����״̬
		{
			// ��������
			return true;
		}
		case Constants.GS_PLAYING: // ��Ϸ״̬
		{
			// ��������
			return true;
		}
		}

		return true;
	}
	void OnEventGameStart() {
		Init(Constants.INIT_NEWROUND);
		if(m_byRound == 0)
			m_byRound = 1;
		OnRoundInfoChange();
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
			}
		}
		m_bTableStarted = true;
		m_bGameStarted = true;
	}
	public void DoDismissRoomByOverTime(){
		OnEventGameEnd(0, Constants.GAME_END_DISMISS);
	}
	void OnEventGameEnd(int bySeatID,int cbReason){
		if(isZuJuType()){
			OnEventGameEndZuJu(bySeatID,cbReason);
		}else if(isGoldType()){
			onEventGameEndGold(bySeatID,cbReason);
		}else if(isDwcType()){
			onEventGameEndDwc(bySeatID,cbReason);
		}
	}
	void onEventGameEndDwc(int bySeatID, int cbReason) {
		if (cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			QpGameMgr.getInstance().OnDismissRoom(this);
		} 
	}
	void onEventGameEndGold(int bySeatID, int cbReason) {
		if (cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			QpGameMgr.getInstance().OnDismissRoom(this);
		} 
	}
	void OnEventGameEndZuJu(int bySeatID, int cbReason) {
	
	}

	static int log_counter = 0;


	void OnDealQiangZhuang() {

	}
	
	void QiangZhuang(int byZhuang)
	{
		m_curStage = "STAGE_QIANGZHUANG";
		needDealTime = 5;
		
		SUBCMD_S_DingZhuang cmd = new SUBCMD_S_DingZhuang();
		cmd.lUid = 0;
		cmd.wChairID = 0;
		cmd.wPower = 0;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());		
	}

	void OnDealXiaZhu() {
		m_curStage = "STAGE_XIAZHU";
		needDealTime = 0;

	}
	
	int GetNextUser(int bySeatID)
	{
		int wNextUser = 0;
		for (int i = 1; i <= m_maxUserNum; i++) {
			wNextUser = (bySeatID + i) % m_maxUserNum;
			if (m_pIUserItem[wNextUser].dwUserID > 0) {
				return wNextUser;
			}
			
		}
		return 0;
	}

	public static long currDealTime = 0;
	void OnDealAI(float dt) {

	}
	public int GetNeedAddFish(int rand1){
		if(rand1 == 0){
			rand1 = random(0,10000);
		}else if(rand1 == 1){
			rand1 = random(0,6500);
		}
		
		int[] vecFishType1 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
		int maxVec1 = 100;
		
		int[] vecFishType2 = {21,22,23,31,32,33,34,35,35};
		int maxVec2 = 10;
		
		int[] vecFishType3 = {51,52,53};
		int maxVec3 = 1;
		
		int[] vecFishType4 = {101,102,103};
		int maxVec4 = 2;
		
		int randAddFishType = 0;
		
		if(rand1 < 9200){
			randAddFishType = vecFishType1[rand1 % 20];
		}else if(rand1 < 9500){
			randAddFishType = vecFishType2[rand1 % 9];
			int tempAllNum = 0;
			for(int i = 0;i < 9;i++){
				if(m_mapFishNumber.containsKey(vecFishType2[i])){
					tempAllNum += m_mapFishNumber.get(vecFishType2[i]);
				}
			}
			if(tempAllNum >= maxVec2){
				randAddFishType = 0;
			}
		}else if(rand1 < 9990){
			randAddFishType = vecFishType4[rand1 % 3];
			
			int tempAllNum = 0;
			for(int i = 0;i < 3;i++){
				if(m_mapFishNumber.containsKey(vecFishType4[i])){
					tempAllNum += m_mapFishNumber.get(vecFishType4[i]);
				}
			}
			if(tempAllNum >= maxVec4){
				randAddFishType = 0;
			}
		}else{
			randAddFishType = vecFishType3[rand1 % 3];
			int tempAllNum = 0;
			
			for(int i = 0;i < 3;i++){
				if(m_mapFishNumber.containsKey(vecFishType3[i])){
					tempAllNum += m_mapFishNumber.get(vecFishType3[i]);
				}
			}
			if(tempAllNum >= maxVec3){
				randAddFishType = 0;
			}
		}
		if(!g_mapFishCfg.containsKey(randAddFishType))
			return 0;
		FishConfig fishConfig = g_mapFishCfg.get(randAddFishType);
		if(!m_mapFishNumber.containsKey(randAddFishType)){
			m_mapFishNumber.put(randAddFishType,0);
		}
		int fishNum = m_mapFishNumber.get(randAddFishType);
		if(fishNum < fishConfig.m_iMaxLimit || fishConfig.m_iMaxLimit == 0){
			fishNum++;
		}else{
			randAddFishType = 0;
		}
		return randAddFishType;
	}
	public void RemoveInvalid(){
		long tnow_ms = System.currentTimeMillis();
		for(int i = 0;i < m_vecAddFishHistory.length;i++){
			if(m_vecAddFishHistory[i].m_tBirthTime > 0){
				if(tnow_ms - m_vecAddFishHistory[i].m_tBirthTime > 5000 * 11){
					m_vecAddFishHistory[i].clean();
				}
			}
		}
		Iterator<Map.Entry<Integer, FishInfo>> it = m_mapFishs.entrySet().iterator();
		while(it.hasNext()){
			Map.Entry<Integer, FishInfo> entry = it.next();
			FishInfo tmpFishInfo = entry.getValue();
			if(tmpFishInfo.m_iOdds == 0){
				System.out.println("tmpFishInfo.m_iOdds == 0");
			}
			if(tmpFishInfo.m_iStatus == Constants.FISH_STATUS_DEAD || tnow_ms - tmpFishInfo.m_tBirthTime > 5000 * 11){
				int fishNum = m_mapFishNumber.get(tmpFishInfo.m_iFishType);
				fishNum--;
				if(fishNum < 0){
					fishNum = 0;
				}
				for(int i = 0;i < 50;i++){
					if(m_vecAddFishHistory[i].m_tBirthTime > 0){
						for(int j = 0;j < 10;j++){
							if(m_vecAddFishHistory[i].m_iFishId[j] == tmpFishInfo.m_iFishType){
								m_vecAddFishHistory[i].m_iFishId[j] = 0;
							}
						}
					}
				}
				it.remove();
			}
		}
	}
	public void AddToHistory(MSG_AddFish msg){
		long minBirthTime = 0;
		int nReplacePos = -1;
		
		for(int i = 0;i < m_vecAddFishHistory.length;i++){
			if(m_vecAddFishHistory[i].m_tBirthTime == 0){
				try {
					BeanUtils.copyProperties(m_vecAddFishHistory[i],msg);
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}else{
				if(minBirthTime == 0){
					minBirthTime = m_vecAddFishHistory[i].m_tBirthTime;
					nReplacePos = i;
				}
				
				if(m_vecAddFishHistory[i].m_tBirthTime < minBirthTime){
					minBirthTime = m_vecAddFishHistory[i].m_tBirthTime;
					nReplacePos = i;
				}
			}
		}
		if(nReplacePos >= 0){
			try {
				BeanUtils.copyProperties(m_vecAddFishHistory[nReplacePos],msg);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public void SendHistory(int _Uid){
		long tnow_ms = System.currentTimeMillis();
		RemoveInvalid();
		for(int i = 0;i < m_vecAddFishHistory.length;i++){
			if(m_vecAddFishHistory[i].m_tBirthTime > 0){
				SUBCMD_S_AddFish cmd = new SUBCMD_S_AddFish();
				try {
					BeanUtils.copyProperties(cmd,m_vecAddFishHistory[i]);
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				cmd.m_tNowTime = tnow_ms;
				String sData = cmd.toString();
				dthall.getInstance().onSend(_Uid,sData);
			}
		}
	}
	public int loadFishs(int sencs,HashMap<Integer,FishInfo> mapFishs) throws IOException{
		mapFishs.clear();
		String filename = "conf/sencs" + sencs + ".json";
		BufferedReader reader = null;
		String jsonData = "";
		try {
			reader = new BufferedReader(new FileReader(filename));
			String contentLine = null;
			contentLine = reader.readLine();
			while (contentLine != null) {
				jsonData += contentLine;
				contentLine = reader.readLine();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {  
			try {
				if (reader != null) {
					reader.close();
				}
			} catch (IOException e) {
				System.out.println("Error in closing the BufferedReader");
			}
		}
		if(jsonData == ""){
			return 0;
		}
		int addFishNum = 0;
		long tnow_ms = System.currentTimeMillis();
		if(jsonData.startsWith("{")){
			JSONObject json = JSONObject.fromObject(jsonData);
			if(json.containsKey("fishs")){
				String fishs = json.getString("fishs");
				JSONArray fisharray = JSONArray.fromObject(fishs);
				long cur_time = System.currentTimeMillis();
				for(int i = 0;i < fisharray.size();i++){
					JSONObject obj = fisharray.getJSONObject(i);
					if(obj.containsKey("m_id") && obj.containsKey("type_id")){
						int m_id = obj.optInt("m_id");
						int type_id = obj.optInt("type_id");
						
						FishConfig fishCfg = g_mapFishCfg.get(type_id);
						FishInfo fishInfo = new FishInfo();
						fishInfo.m_tBirthTime = tnow_ms;
						fishInfo.m_iFishID = m_id;
						fishInfo.m_iFishType = type_id;
						fishInfo.m_iPathId = 0;
						fishInfo.m_iBlood = fishCfg.m_iBlood;
						fishInfo.m_iStatus = Constants.FISH_STATUS_NORMAL;
						fishInfo.m_iOdds = fishCfg.m_iOdds;
						fishInfo.m_iEatCoin = 0;
						m_mapFishs.put(m_id, fishInfo);
						addFishNum++;
					}
				}
			}
		}
		return addFishNum; 
	}
	public  long currDealTime1 = 0;
	public void OnDeal(int dt) {
		if(currDealTime1 == 0){
			currDealTime1 = System.currentTimeMillis();
		}else{
			long time = System.currentTimeMillis();
			if((time - currDealTime1) >= 1000){
				currDealTime1 = time;
			}else{
				return;
			}
		}
		if(GetPlayerCount() > 0){
			int rand1 = random(0,10000);
			int rand2 = random(0,10000);
			long tnow_ms = System.currentTimeMillis();
			if(m_LastYuChaoTime >= tnow_ms || m_LastFreezeTime >= tnow_ms){
				return;
			}
			if(m_LastYuChaoTime != 0 && m_LastYuChaoTime + (60 * 60 * 24 * 1000) <= tnow_ms){
				//return;
				m_LastYuChaoTime = tnow_ms;
				int []sencs_ids = {4,5,6,7};
				int []sencs_id_times = {36 + 40,45 + 40,42+40,70};
				
				int yuchao_id = rand1 % 3;
				SUBCMD_S_AddYuChao cmd = new SUBCMD_S_AddYuChao();
				cmd.m_tBirthTime = tnow_ms;
				cmd.m_tNowTime = tnow_ms;
				cmd.m_iYuChaoType = sencs_ids[yuchao_id];
				cmd.m_iStartID = 10000;
				m_LastYuChaoTime = System.currentTimeMillis() + (1000 * sencs_id_times[yuchao_id]);
				try {
					loadFishs(cmd.m_iYuChaoType,m_mapOtherFishs);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				String sData = cmd.toString();
				for(int wChairID = 0;wChairID < 4;wChairID++){
					if(m_pIUserItem[wChairID].dwUserID > 0){
						SendData(wChairID,sData);
					}
				}
			}else{
				//add fish
				int addFishType = GetNeedAddFish(0);
				if(addFishType > 0){
					if(!g_mapFishCfg.containsKey(addFishType)){
						return;
					}
					FishConfig addFishCfg = g_mapFishCfg.get(addFishType);
					
					int bornLimit = addFishCfg.m_iBornLimit > 0 ? addFishCfg.m_iBornLimit : 1;
					int speed = addFishCfg.m_iSpeed > 0 ? addFishCfg.m_iSpeed : 100;
					
					int iFishNum = rand2 % bornLimit + 1;
					
					if(iFishNum > 8){
						return;
					}
					if(rand1 < 5000){
						if(iFishNum > 4){
							iFishNum = iFishNum / 2 + 1;
						}
					}
					
					SUBCMD_S_AddFish cmd = new SUBCMD_S_AddFish();
					cmd.m_tBirthTime = tnow_ms;
					cmd.m_tNowTime = tnow_ms;
					cmd.m_iFishType = addFishType;
					for(int i = 0;i < iFishNum;i++){
						m_iNextFishID++;
						m_iNextFishID = m_iNextFishID % 10000;
						cmd.m_iFishId[i] = m_iNextFishID;
					}
					
					cmd.m_iPathId = rand2 % 10000;
					cmd.m_iNum = iFishNum;
					cmd.m_iDirection = rand1 %2 + 1;
					cmd.m_iDeviation = rand1 % 3;
					cmd.m_iSpeed = speed;
					
					MSG_AddFish msg = new MSG_AddFish();
					msg.copyFromAddFishCmd(cmd);
					
					String sData = cmd.toString();
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,sData);
						}
					}
					
					RemoveInvalid();
					AddToHistory(msg);
					
					if(g_mapFishCfg.containsKey(msg.m_iFishType)){
						FishConfig fishConfig = g_mapFishCfg.get(msg.m_iFishType);
						for(int i = 0;i < 10;i++){
							if(msg.m_iFishId[i] > 0){
								FishInfo fishInfo = new FishInfo();
								fishInfo.m_tBirthTime = msg.m_tBirthTime;
								fishInfo.m_iFishID = msg.m_iFishId[i];
								fishInfo.m_iFishType = msg.m_iPathId;
								fishInfo.m_iBlood = fishConfig.m_iBlood;
								fishInfo.m_iStatus = 0;
								fishInfo.m_iOdds = fishConfig.m_iOdds;
								fishInfo.m_iEatCoin = 0;
								m_mapFishs.put(fishInfo.m_iFishID, fishInfo);
							}
						}
					}
				}
			}
		}else{
			m_LastYuChaoTime = System.currentTimeMillis();
		}
	}

	static int randRobotIndex = 999;

	void AddRobot() {

	}

	void Handle_onJoin(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < m_maxUserNum) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
		}

		SUBCMD_S_Join cmd = new SUBCMD_S_Join();

		String sData = cmd.getJsonData();
		SendData(_Uid, sData);
	}

	void Handle_onReady(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < m_maxUserNum) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
			m_UserStatus[bySeatID] = Constants.US_READY;
		}
		int roomUserNumber = 0;
		UserCntReady = 0;
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
				UserCntReady++;
			}
			if(m_pIUserItem[i].wChairID>=0){
				roomUserNumber++;
			}
		}
		
		SUBCMD_S_Ready cmd = new SUBCMD_S_Ready();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = bySeatID;
		cmd.m_dwTableID = m_dwTableID;
		cmd.m_byRound = m_UserStatus;
		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		
		if(UserCntReady==roomUserNumber){
			OnEventGameStart();
		}
	}

	void Handle_onRobot(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < m_maxUserNum) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
		}
		int cntPlayer = 0;
		for (int i = 0; i < m_maxUserNum; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		if (cntPlayer < m_maxUserNum) {
			for (int i = 0; i < m_maxUserNum - cntPlayer; i++) {
				AddRobot();
			}
		}
	}

	void Handle_onBiaoQing(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iBiaoQingIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onYuYin(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iYuYinIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onSongLi(int _Uid, String vecArg[]) {
	}

	void Handle_onChat(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 2)
			return;
		String strContent = vecArg[1];

		SUBCMD_S_Chat cmd = new SUBCMD_S_Chat();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.szContent = strContent;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onVoice(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 3)
			return;
		int seconds = Constants.atoi(vecArg[1]);
		String strVoiceURL = vecArg[2];

		SUBCMD_S_Voice cmd = new SUBCMD_S_Voice();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		cmd.szVoiceURL = strVoiceURL;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}
	void Handle_onExpr(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		int uid1 = Integer.parseInt(vecArg[1]);
		int uid2 = Integer.parseInt(vecArg[2]);
		int index = Integer.parseInt(vecArg[3]);
		
		SUBCMD_S_ExprMsg cmd = new SUBCMD_S_ExprMsg();
		cmd.m_uid1 = uid1;
		cmd.m_uid2 = uid2;
		cmd.m_index = index;
		
		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}
	void Handle_onVoiceMsg(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		float seconds = Float.parseFloat(vecArg[1]);
		
		SUBCMD_S_VoiceMsg cmd = new SUBCMD_S_VoiceMsg();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		
		cmd.data = vecArg[2];
		cmd.m_maxClip = Integer.parseInt(vecArg[3]);
		cmd.m_currClip = Integer.parseInt(vecArg[4]);
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	public int FindSeat(int _Uid) {
		for (int bySeatID = 0; bySeatID < m_maxUserNum; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}
	public int FindCannonCost(int _Uid){
		int iCannonNum = g_vecCannonLevels.size();
		for(int i = 0;i < 4;i++){
			if(m_pIUserItem[i].dwUserID == _Uid){
				return g_vecCannonLevels.get(m_pIUserItem[i].cannonLevel % iCannonNum);
			}
		}
		return 0;
	}
	public int m_DealTime = 0;

	public int getDealTime() {
		return 1;
	}
	
	public boolean m_bRemove = false;

	public void DelayRemove() {
		m_bRemove = true;
	}

	public void ResetKillFlag() {
		m_bRemove = false;
	}

	public boolean ShouldBeRemoved() {
		return m_bRemove;
	}
	
	public void Handle_onLock(Integer lUid, String[] vecArg) {		
		if (vecArg.length < 2)
			return;
		if ( m_bTableStarted && m_pIUserItem[0].dwUserID == lUid) {
			int index = Constants.atoi(vecArg[1]);
			m_locked = index;			
			
		}
	}
	void Handle_InBack(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
				
		SUBCMD_S_InBack cmd = new SUBCMD_S_InBack();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}

	void Handle_InFore(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		
		SUBCMD_S_InFore cmd = new SUBCMD_S_InFore();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	void Handle_GameIap(int _Uid,String vecArg[]){
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user == null){
			return;
		}
		SUBCMD_S_GameIap cmd = new SUBCMD_S_GameIap();
		cmd.uid = _Uid;
		cmd.seat = wChairID;
		cmd.coin = user.getCoin(0);
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	@Override
	public String getRoomInfo() {
		// TODO �Զ����ɵķ������
		//m_lStartTime
		//m_pIUserItem
		// m_bTableStarted;
		// m_byRound;
		// m_byMaxRound;
		//m_dwTableID
		String roomInfo = String.format("%s|%s|%s|%s|%s", 
				m_pIUserItem[0].GetUserInfo(), //#
				m_pIUserItem[1].GetUserInfo(), 
				m_pIUserItem[2].GetUserInfo(), 
				m_pIUserItem[3].GetUserInfo(),
				m_pIUserItem[4].GetUserInfo()
				);
		String descInfo = String.format("房间类型：疯狂捕鱼  %d/%d局",m_byRound,m_byMaxRound);
		roomInfo = String.format("%s|%d|%d|%s", roomInfo,m_dwTableID,m_lStartTime,descInfo);
		
		return roomInfo;
	}
	
	public boolean isM_bGameStarted(){
		return m_bGameStarted;
	}
	
	@Override
	public int getPlayerCount() {
		return GetPlayerCount();
	}
	@Override
	public int getCostGem() {
		return m_byCostGem;
	}
	@Override
	public int getStatus() {
		if(m_bTableStarted == false)
		{
			return 0;
		}
		return 1;
	}

	@Override
	public String getRoomDesc() {
		return null;
	}

	@Override
	public int getCellScore() {
		return 0;
	}

	@Override
	public int getMinScore() {
		return 0;
	}

	@Override
	public String getPayway() {
		return m_payWay;
	}

	@Override
	public String GetRoundInfo() {
		return "" + m_byRound + "/" +  m_byMaxRound;
	}
	public boolean Calculate(int _Uid,long eatCoin,long cannonCost,long odds,long userLuckCoin,long blood){
		int random1 = random(0,10000);
		int factor = 0;
		if(m_iBase > 0 && m_iBase < 10000){
			factor = (int) (cannonCost / m_iBase);
		}
		if(factor > 10){
			factor = (int) (10 + Math.sqrt(factor - 10));
		}
		if(factor < 30){
			factor = 30;
		}
		if(blood <= 0 && eatCoin * 3 >= cannonCost * odds){//每次概率一样
			if(odds < 5){
				if(random1 < 2500 + factor * 10 - odds)
					return true;
			}else if(odds < 10){
				if(random1 < 2000 + factor * 10 - odds)
					return true;
			}else if(odds < 20){
				if(random1 < 1000 + factor * 10 - odds)
					return true;
			}else if(odds < 30){
				if(random1 < 700 + factor * 10 -odds)
					return true;
			}else if(odds < 50){
				if(random1 < 400 + factor * 10 - odds)
					return true;
			}else if(odds < 80){
				if(random1 < 300 + factor * 10 - odds){
					return true;
				}
			}else{
				if(random1 < 220 + factor * 10 - odds)
					return true;
			}
			/*
			if(eatCoin <= cannonCost * (odds - 1)){
				return true;
			}
			*/
		}
		return false;
	}
	public static boolean isNumeric(String str) {
		for (int i = 0; i < str.length(); i++) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}
	void Handle_onJoinTable(int _lUid,String[] vecArg){
	}
	void Handle_onLeaveTable(int _lUid,String[] vecArg){
	}
	void Handle_onCannon(int _Uid,String[] vecArg){
		if(vecArg.length < 2)
			return;
		int iCannonLevel = Integer.parseInt(vecArg[1]);
		//int cannonLevels[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000 };
		int iCannonNum = g_vecCannonLevels.size();
		int iCost = g_vecCannonLevels.get(iCannonLevel % iCannonNum);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			int wSeatID = FindSeat(_Uid);
			if(wSeatID > 0){
				SUBCMD_S_AdjustCannon cmd = new SUBCMD_S_AdjustCannon();
				cmd.m_lUid = _Uid;
				cmd.m_iSeat = wSeatID;
				cmd.m_iCannonLevel = iCannonLevel;
				cmd.m_iCost = iCost;
				m_pIUserItem[wSeatID - 1].cannonLevel = cmd.m_iCannonLevel;
				String sData = cmd.toString();
				for(int wChairID = 0;wChairID < 4;wChairID++){
					if(m_pIUserItem[wChairID].dwUserID > 0){
						SendData(wChairID,sData);
					}
				}
			}
		}
	}
	void Handle_onFire(int _Uid,String[] vecArg){
		if(vecArg.length < 2)
			return;
		int Rotation = Integer.parseInt(vecArg[1]);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			int wSeatID = FindSeat(_Uid);
			if(wSeatID > 0 && m_pIUserItem[wSeatID - 1].cannonLevel >= 0 && m_pIUserItem[wSeatID - 1].cannonLevel < 60){
				int userAllCoin = user.getCoin(0);
				//int cannonLevels[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000 };
				int iCannonNum = g_vecCannonLevels.size();
				int iCost = g_vecCannonLevels.get(m_pIUserItem[wSeatID - 1].cannonLevel % iCannonNum);
				if(userAllCoin < iCost)
					return;
				SUBCMD_S_DoFire cmd = new SUBCMD_S_DoFire();
				cmd.m_lUid = _Uid;
				UserRedisInfo userRedis = user.getUserRedisInfo();
				userRedis.setFishIntValue("FishLuckCoin", iCost);
				userRedis.setFishIntValue("FishUseCoin", iCost);
				cmd.m_lTotalCoin = user.getCoin(-iCost);
				cmd.m_iSeat = wSeatID;
				cmd.m_iCannonLevel = m_pIUserItem[wSeatID - 1].cannonLevel;
				cmd.m_rotation = Rotation;
				String sData = cmd.toString();
				for(int wChairID = 0;wChairID < 4;wChairID++){
					if(m_pIUserItem[wChairID].dwUserID > 0){
						SendData(wChairID,sData);
					}
				}
			}
		}
	}
	void Handle_onCatch(int _Uid,String[] vecArg){
		if(vecArg.length != 3 && vecArg.length != 4)
			return;
		int[] iFishId = new int[10];
		String[] vecArg2 = vecArg[1].split(",");
		
		for(int i = 0;i < vecArg2.length;i++){
			if(isNumeric(vecArg2[i])){
				iFishId[i] = Integer.parseInt(vecArg2[i]);
			}
		}
		vecArg2 = vecArg[2].split(",");
		if(vecArg2.length == 2)
			return;
		int ptX = Integer.parseInt(vecArg2[0]);
		int ptY = Integer.parseInt(vecArg2[1]);
		
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			UserRedisInfo redisData = user.getUserRedisInfo();
			int cntPlayer = GetPlayerCount();
			int rand1 = random(0,10000);
			int wSeatID = FindSeat(_Uid);
			int cannonCost = FindCannonCost(_Uid);//当前炮花费
			if(this.isGoldType()){
				if(user.getCoin(0) <= 100 || user.getCoin(0) < cannonCost){
					cannonCost = 1;
				}
			}else if(this.isDwcType()){
				////每炮的消耗
			}
			int fireUseCoin = redisData.getFishIntValue("FireUseCoin");
			redisData.setFishIntValue("FireUseCoin", fireUseCoin - cannonCost);
			fireUseCoin = redisData.getFishIntValue("FireUseCoin");
			if(fireUseCoin < 0){
				redisData.setFishIntValue("FireUseCoin",0);
				return;
			}
			boolean isYuChaoYu = false;//
			FishInfo fishInfo = m_mapFishs.get(iFishId[0]);
			if(iFishId[0] >= 10000){
				isYuChaoYu = true;
				fishInfo = m_mapOtherFishs.get(iFishId[0]);
			}
			FishConfig addFishCfg = null;
			if(fishInfo != null){
				addFishCfg = g_mapFishCfg.get(fishInfo.m_iFishType);
				if(addFishCfg == null)
					return;
			}
			if(m_iBase == 0){
				m_iBase = 1;
			}
			int critical_damage = 0;
			if(cannonCost > 0){
				int Critical = (int) (40 - Math.sqrt(10 + cannonCost / m_iBase));
				if(Critical < 13){
					Critical = 13;
				}
				if(rand1 % Critical == 0){
					critical_damage = Critical / 3;
				}
			}
			if(rand1 % 1000 == 999){
				critical_damage = 999;
			}
			int addCoin = addFishCfg.m_iOdds * cannonCost;
			fishInfo.m_iEatCoin += cannonCost;//吃金币
			fishInfo.m_iBlood -= random(0,7 - cntPlayer) + critical_damage;
			
			int userLuckCoin = redisData.getFishIntValue("LuckCoin");
			int eatCoin = fishInfo.m_iEatCoin;
			boolean isCatch = critical_damage == 999?true : Calculate(_Uid,eatCoin,cannonCost,addFishCfg.m_iOdds,userLuckCoin,fishInfo.m_iBlood);
			if(addCoin == 0){
				isCatch = false;
				System.out.println("Error Catch Fish"+ addFishCfg.m_iOdds+ cannonCost);
			}
			if(isCatch){
				System.out.println("is Catch");
				fishInfo.m_iStatus = Constants.FISH_STATUS_DEAD;
				
				SUBCMD_S_Catch cmd = new SUBCMD_S_Catch();
				cmd.m_lUid = _Uid;
				cmd.m_iSeat = wSeatID;
				cmd.m_xPoint = ptX;
				cmd.m_yPoint = ptY;
				cmd.m_iOdds = addFishCfg.m_iOdds;
				cmd.m_iAddCoin = addCoin;
				cmd.m_iAddGem = 0;
				redisData.setFishIntValue("LuckCoin", userLuckCoin - addCoin);
				
				int factor = user.getGem(0) * 10;
				int maxCannonLevel = redisData.getFishIntValue("CannonLevel");
				if(maxCannonLevel < 5){
					if(factor > 460){
						factor = 460;
					}
					if(rand1 < 2000 - factor * 4){
						cmd.m_iAddGem = 1;//掉钻石
					}
				}else if(maxCannonLevel < 10){
					if(factor > 310){
						factor = 310;
					}
					if(rand1 < 1000 - factor * 3){
						cmd.m_iAddGem = 1;//掉钻石
					}
				}else if(maxCannonLevel < 20){
					if(factor > 170){
						factor = 170;
					}
					if(rand1 < 400 - factor * 2){
						cmd.m_iAddGem = 1;//掉钻石
					}
				}else if(maxCannonLevel < 40){
					if(factor > 250){
						factor = 250;
					}
					if(rand1 < 300 - factor){
						cmd.m_iAddGem = 1;//掉钻石
					}
				}else{
					if(factor > 150){
						factor = 150;
					}
					if(rand1 < 200 - factor){
						cmd.m_iAddGem = 1;//掉钻石
					}
				}
				if(this.isGoldType()){
					cmd.m_iTotalCoin = user.getCoin((int)(cmd.m_iAddCoin));
					cmd.m_iTotalGem = user.getGem(cmd.m_iAddGem);
				}else{
					
				}
				try {
					BeanUtils.copyProperties(cmd.m_iFishId,iFishId);
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				String sData = cmd.toString();
				for(int wChairID = 0;wChairID < 4;wChairID++){
					if(m_pIUserItem[wChairID].dwUserID > 0){
						SendData(wChairID,sData);
					}
				}
				if(false){
					int give_rate = (600 - 20 * maxCannonLevel);
					if(give_rate < 200){
						give_rate = 200;
					}
					if(false){
						SUBCMD_S_GiveItem giveCmd = new SUBCMD_S_GiveItem();
						giveCmd.m_lUid = _Uid;
						giveCmd.m_iSeat = wSeatID;
						giveCmd.m_xPoint = ptX;
						giveCmd.m_yPoint = ptY;
						int id_max = 10000;
						int id_lock = 300;
						int id_lamp = 250;
						int id_freeze = 100;
						if(random(0,id_max) < id_lock){
							//锁定
							SUBCMD_S_GiveItem.addGiveItem(giveCmd,Constants.ITEM_LOCK, 1);
						}
						if(random(0,id_max) < id_lamp){
							//神灯
							SUBCMD_S_GiveItem.addGiveItem(giveCmd,Constants.ITEM_LAMP, 1);
						}
						if(random(0,id_max) < id_freeze){
							//冰冻
							SUBCMD_S_GiveItem.addGiveItem(giveCmd,Constants.ITEM_FREEZE, 1);
						}else{
							if(random(0,id_max) < id_max / 2){
								//锁定
								SUBCMD_S_GiveItem.addGiveItem(giveCmd,Constants.ITEM_LOCK, 1);								
							}else{
								//神灯
								SUBCMD_S_GiveItem.addGiveItem(giveCmd,Constants.ITEM_LAMP, 1);
							}
						}
						String giveData = giveCmd.toString();
						for(int wChairID = 0;wChairID < 4;wChairID++){
							if(m_pIUserItem[wChairID].dwUserID > 0){
								SendData(wChairID,giveData);
							}
						}
					}
				}
			}
		}
	}
	public boolean ConsumeItem(int _Uid,int item_id,int item_used,FishUseItemResult result){
		if(item_id <= 0 || item_used < 1)
			return false;
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			UserRedisInfo redisData = user.getUserRedisInfo();
			int hasCount = redisData.getFishIntValue("item_" + item_id);
			if(hasCount >= item_used){
				redisData.setFishIntValue("item_" + item_id, hasCount - item_used);
				return true;
			}else{
				if(this.isGoldType()){
					int iCostGem = 0;
					if(item_id == Constants.ITEM_FREEZE){
						iCostGem = 5;
					}else if(item_id == Constants.ITEM_LOCK){
						iCostGem = 2;
					}else if(item_id == Constants.ITEM_LAMP){
						iCostGem = 2;
					}else if(item_id == Constants.ITEM_WILD){
						iCostGem = 20;
					}else if(item_id == Constants.ITEM_NUCLEAR){
						iCostGem = 200;
					}
					if(user.getGem(0) >= iCostGem){
						user.getGem(-iCostGem);
						result.out_costGem = iCostGem;
						return true;
					}
				}else if(this.isDwcType()){
					double iCostRmb = 0.0;
					if(item_id == Constants.ITEM_FREEZE){
						iCostRmb = 0.5;
					}else if(item_id == Constants.ITEM_LOCK){
						iCostRmb = 0.2;
					}else if(item_id == Constants.ITEM_LAMP){
						iCostRmb = 0.2;
					}else if(item_id == Constants.ITEM_WILD){
						iCostRmb = 2;
					}else if(item_id == Constants.ITEM_NUCLEAR){
						iCostRmb = 20;
					}
					if(user.getRmb1v1Value() >= iCostRmb){
						user.addRmb1v1Value(-iCostRmb);
						result.out_costRmb = iCostRmb;
						return true;
					}
				}
			}
		}
		return false;
	}
	void Handle_onUseDaoJu(int _Uid,String[] vecArg){
		if(vecArg.length < 2)
			return;
		String daoju = vecArg[1];
		int iItemId = 0;
		int xPos = 0;
		int yPos = 0;
		FishUseItemResult itemResult = new FishUseItemResult();;
		itemResult.out_cntItem = 0;
		itemResult.out_costGem = 0;
		int item_used = 1;
		if(vecArg.length >= 3){
			item_used = Integer.parseInt(vecArg[2]);
		}
		if(vecArg.length == 5){
			xPos = Integer.parseInt(vecArg[3]);
			yPos = Integer.parseInt(vecArg[3]);
		}
		if(daoju.equals("lock")){
			if(!ConsumeItem(_Uid,Constants.ITEM_LOCK,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_LOCK;
		}else if(daoju.equals("freeze")){
			if(!ConsumeItem(_Uid,Constants.ITEM_FREEZE,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_FREEZE;
		}else if(daoju.equals("wild")){
			if(!ConsumeItem(_Uid,Constants.ITEM_WILD,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_WILD;
		}else if(daoju.equals("lamp")){
			if(!ConsumeItem(_Uid,Constants.ITEM_LAMP,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_LAMP;
		}else if(daoju.equals("bomb")){
			if(!ConsumeItem(_Uid,Constants.ITEM_BOMB,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_BOMB;
		}else if(daoju.equals("nuclear")){
			if(!ConsumeItem(_Uid,Constants.ITEM_NUCLEAR,1,itemResult)){
				return;
			}
			iItemId = Constants.ITEM_NUCLEAR;
		}
		System.out.println("use daoju" + iItemId + daoju);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			int wSeatID = FindSeat(_Uid);
			if(wSeatID > 0){
				SUBCMD_S_UseItem cmd = new SUBCMD_S_UseItem();
				cmd.m_lUid = _Uid;
				cmd.m_iSeat = wSeatID;
				cmd.m_iItemId = 1;
				cmd.m_iItemCount = itemResult.out_cntItem;
				cmd.m_iCostCoin = 0;
				cmd.m_iTotalCoin = user.getCoin(0);
				cmd.m_iTotalGem = user.getGem(0);
				String sData = cmd.toString();
				
				for(int wChairID = 0;wChairID < 4;wChairID++){
					if(m_pIUserItem[wChairID].dwUserID > 0){
						SendData(wChairID,sData);
					}
				}
				
				if(iItemId == Constants.ITEM_FREEZE){//冰冻
					SUBCMD_S_Freeze itemcmd = new SUBCMD_S_Freeze();
					itemcmd.m_lUid = _Uid;
					itemcmd.m_iSeat = wSeatID;
					itemcmd.m_iRemainTime = 10;
					m_LastFreezeTime = System.currentTimeMillis() + (itemcmd.m_iRemainTime * 1000);
					String itemData = cmd.toString();
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,itemData);
						}
					}
				}else if(iItemId == Constants.ITEM_LAMP){
					int rand_lamp = random(0,10000);
					SUBCMD_S_Lamp itemcmd = new SUBCMD_S_Lamp();
					itemcmd.m_lUid = _Uid;
					itemcmd.m_iSeat = wSeatID;
					itemcmd.m_iFishType = 31 + rand_lamp % 6;
					if(itemcmd.m_iFishType == 36)
						itemcmd.m_iFishType = 32;
					m_iNextFishID++;
					m_iNextFishID = m_iNextFishID % 10000;
					itemcmd.m_iFishID = m_iNextFishID;
					String itemData = itemcmd.toString();
					
					FishConfig addFishCfg = g_mapFishCfg.get(itemcmd.m_iFishType);
					if(addFishCfg != null){
						FishInfo addFishInfo = new FishInfo();
						addFishInfo.m_iFishID = itemcmd.m_iFishID;
						m_mapFishs.put(addFishInfo.m_iFishID, addFishInfo);
					}
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,itemData);
						}
					}
				}else if(iItemId == Constants.ITEM_LOCK){
					SUBCMD_S_Lock itemcmd = new SUBCMD_S_Lock();
					itemcmd.m_lUid = _Uid;
					itemcmd.m_iSeat = wSeatID;
					itemcmd.m_iRemainTime = 20;
					String itemData = itemcmd.toString();
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,itemData);
						}
					}
				}else if(iItemId == Constants.ITEM_WILD){
					SUBCMD_S_Wild itemcmd = new SUBCMD_S_Wild();
					itemcmd.m_lUid = _Uid;
					itemcmd.m_iSeat = wSeatID;
					String itemData = itemcmd.toString();
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,itemData);
						}
					}
				}				
			}
		}
	}
	void Handle_onUpgradeCannon(int _lUid,String[] vecArg){
		SHMUser user = dthall.getInstance().getUserInfo(_lUid);
		if(user == null)
			return;
		UserRedisInfo redisData = user.getUserRedisInfo();
		int iCurCannonLevel = redisData.getFishIntValue("fishCannonLevel");
		int iNextCannonLevel = iCurCannonLevel + 1;
		
		int cannonLevels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 350, 400,450,500,550,600,650,700,750,800,850,900,950,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000,8500,9000,9500,10000};
		int needGems[] =     {0, 0, 2, 2, 3, 3, 5, 5, 5, 5, 8 , 8 , 8 , 8 , 8 , 10, 10, 10, 10, 20, 20, 20, 20, 30 , 30 , 40 , 50 , 60 , 70 , 80,90,100,110,120,130,140,150,160,170,180,190,200,220,240,260,280,300,320,340,360,380,400,420,440,460,480,500,520,540,560 };
		int giveCoins[] =    {0, 0, 100, 100, 150, 150, 200, 200, 200, 200, 1000, 1000, 2000, 2000, 3000, 3000, 4000, 4000, 5000, 5000, 6000, 6000, 7000, 7000, 8000, 8000, 10000, 10000, 13000, 17000, 20000,20000,20000,20000,20000,30000,30000,30000,30000,30000,40000,40000,40000,40000,40000,50000,50000,50000,50000,50000,50000,60000,60000,60000,60000,80000,80000,80000,80000,80000,80000 };
		
		int LevelCount = cannonLevels.length;
		if(iNextCannonLevel < 60 && iNextCannonLevel < LevelCount && user.getGem(0) >= needGems[iNextCannonLevel]){
			user.getGem(0 - needGems[iNextCannonLevel]);
			user.getCoin(giveCoins[iNextCannonLevel]);
			
			if(iCurCannonLevel == 0)
				iCurCannonLevel  = 1;
			iCurCannonLevel++;
			redisData.setFishIntValue("fishCannonLevel", iCurCannonLevel);
			
			int wSeatID = FindSeat(_lUid);
			if(wSeatID > 0){
				{
					SUBCMD_S_UpgradeCannon cmd = new SUBCMD_S_UpgradeCannon();
					cmd.m_lUid = _lUid;
					cmd.m_iSeat = wSeatID;
					cmd.m_iReault = 1;
					cmd.m_iMaxCannonLevel = iCurCannonLevel;
					cmd.m_iCostGem = needGems[iNextCannonLevel];
					cmd.m_iAddCoin = giveCoins[iNextCannonLevel];
					String sData = cmd.toString();
					
					dthall.getInstance().onSend(_lUid, sData);
					
					m_pIUserItem[wSeatID - 1].cannonLevel = iCurCannonLevel;
				}
				{
					SUBCMD_S_AdjustCannon cmd = new SUBCMD_S_AdjustCannon();
					cmd.m_lUid = _lUid;
					cmd.m_iSeat = wSeatID;
					cmd.m_iCannonLevel = iCurCannonLevel;
					cmd.m_iCost = cannonLevels[iNextCannonLevel];
					String sData = cmd.toString();
					for(int wChairID = 0;wChairID < 4;wChairID++){
						if(m_pIUserItem[wChairID].dwUserID > 0){
							SendData(wChairID,sData);
						}
					}
				}
			}
		}
	}
	void Handle_onUpgradeCannon1(int _Uid,String[] vecArg){
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user == null)
			return;
		UserRedisInfo redisData = user.getUserRedisInfo();
		int iCurCannonLevel = redisData.getFishIntValue("fishCannonLevel");
		int iNextCannonLevel = iCurCannonLevel + 1;
		//int cannonLevels[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 350, 400,450,500,550,600,650,700,750,800,850,900,950,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000,8500,9000,9500,10000 };
		//int needCoins[] = { 0, 0, 100, 100, 150, 150, 200, 200, 200, 200, 1000, 1000, 2000, 2000, 3000, 3000, 4000, 4000, 5000, 5000, 6000, 6000, 7000, 7000, 8000, 8000, 10000, 10000, 13000, 17000, 20000,20000,20000,20000,20000,30000,30000,30000,30000,30000,40000,40000,40000,40000,40000,50000,50000,50000,50000,50000,50000,60000,60000,60000,60000,80000,80000,80000,80000,80000,80000 };
		
		int LevelCount = g_vecCannonLevels.size();
		if(iNextCannonLevel < 60 && iNextCannonLevel < LevelCount && user.getGem(0) >= g_needCoins.get(iNextCannonLevel)){
			user.getCoin(0 - g_needCoins.get(iNextCannonLevel));
			
			if(iCurCannonLevel == 0)
				iCurCannonLevel = 1;
			iCurCannonLevel ++;
			redisData.setFishIntValue("CannonLevel", iCurCannonLevel);
			int wSeatID = FindSeat(_Uid);
			if(wSeatID > 0){
				{
					SUBCMD_S_UpgradeCannon1 cmd = new SUBCMD_S_UpgradeCannon1();
					cmd.m_lUid = _Uid;
					cmd.m_iSeat = wSeatID;
					cmd.m_iMaxCannonLevel = iCurCannonLevel;
					cmd.m_iNeedCoin = g_needCoins.get(iCurCannonLevel);
					
					String sData= cmd.toString();
					m_pIUserItem[wSeatID - 1].cannonLevel = iCurCannonLevel;
					dthall.getInstance().onSend(_Uid,sData);
				}
				{
					SUBCMD_S_AdjustCannon cmd = new SUBCMD_S_AdjustCannon();
					cmd.m_lUid = _Uid;
					cmd.m_iSeat = wSeatID;
					cmd.m_iCannonLevel = iCurCannonLevel;
					cmd.m_iCost = g_vecCannonLevels.get(iCurCannonLevel);
					String sData = cmd.toString();
					for(int wChairdID = 0;wChairdID < 4;wChairdID++){
						SendData(wChairdID,sData);
					}
				}
			}
		}
	}
	void Handle_onGetAlms(int _Uid,String[] vecArg){
		int waitTimes[] = {12,60,120,500};
		
		int timeNum = waitTimes.length;
		int wSeatID = FindSeat(_Uid);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(wSeatID > 0 && user != null){
			long tnow_ms = System.currentTimeMillis();
			
			java.util.Date today = new java.util.Date();
			UserRedisInfo redisData = user.getUserRedisInfo();
			int lastAlmsTime = redisData.getFishIntValue("LastAlmsTime");
			if(lastAlmsTime != 0 && lastAlmsTime * 1000 < 9000 * 100 * 100){
				java.util.Date lastday = new java.util.Date(lastAlmsTime * 1000);
				if(today.getDay() != lastday.getDay() && today.getMonth() != lastday.getMonth() && today.getYear() != lastday.getYear()){
					redisData.setFishIntValue("AlmsTimes",0);
					redisData.setFishIntValue("LastAlmsTime", 0);
				}
			}
			int timesed = redisData.getFishIntValue("AlmsTimes");
			
			if(timesed < timeNum){
				if(lastAlmsTime != 0){
					redisData.setFishIntValue("AlmsTimes", timesed + 1);
					redisData.setFishIntValue("LastAlmsTime", (int)(tnow_ms / 1000));
					
					SUBCMD_S_Alms cmd = new SUBCMD_S_Alms();
					cmd.m_lUid = _Uid;
					cmd.m_iSeat = wSeatID;
					if(this.isDwcType()){
						cmd.m_iAlms = 1;
						user.addRmb1v1Value(1.0);
						m_pIUserItem[wSeatID].lUserRmb += 1.0;
					}else if(this.isGoldType()){
						cmd.m_iAlms = 1000;
						user.getCoin(cmd.m_iAlms);
						m_pIUserItem[wSeatID].lUserCoin += 1000;
					}
					String sData = cmd.toString();
					dthall.getInstance().onSend(_Uid, sData);
				}else{
					if(lastAlmsTime == 0){
						lastAlmsTime = (int) ((tnow_ms + (waitTimes[timesed] * 1000)) /1000);
						redisData.setFishIntValue("LastAlmsTime", lastAlmsTime);
					}
					SUBCMD_S_AlmsCountDown cmd = new SUBCMD_S_AlmsCountDown();
					cmd.m_lUid = _Uid;
					cmd.m_iSeat = wSeatID;
					cmd.m_iCountDown = (int) (lastAlmsTime - (int)(tnow_ms / 1000));
					String sData = cmd.toString();
					
					dthall.getInstance().onSend(_Uid, sData);
				}
			}
		}
	}
}
